< previous page page_341 next page >

Page 341
Getting a List of Errors
Sometimes its not always easy to look up the errors Visual Basic generates. You can press F1 and attempt to look for the error codes Visual Basic has defined. However, Ive created a sample program that will generate a list of common Visual Basic errors (see Figure 17.3).
Examples Filename: ListErrors.frm
8160-0341a.gif
Figure 17.3
List of errors.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdErrorList_Click()
   Dim intLoop As Integer

   For intLoop = 1 To 32766
      If Error(intLoop) <> _
         "Application-defined or object-defined error" Then
         lstErrors.AddItem intLoop & vbTab & Error(intLoop)
      End If
   Next intLoop
End Sub
This code loops through all the error numbers in the range of 1 to 32,766. This is the valid range of error numbers for Visual Basic. Each time through the loop, the loop number is passed to the Error() function. This function returns the description of the error that corresponds to that number. There are other error numbers you may receive from the Err object, but these error numbers come from DLL files youve referenced in your application.
The Error() function returns either a valid error description or, if the error number youre trying to retrieve is not defined, the string Application-defined or object-defined error will be returned. This means that the designers of Visual Basic havent assigned an error to this particular error number.

 
< previous page page_341 next page >

If you like this book, buy it!